﻿<Window x:Class="Demos.Heap.View"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Local="clr-namespace:Demos.Heap"
        Title="Heap" Height="550" Width="525" SizeChanged="WindowOnSizeChanged">

    <Window.Resources>
        <DataTemplate DataType="{x:Type Local:Caja}">
            <Grid>
                <Rectangle Stroke="Black" StrokeThickness="1" Name="rectangulo"
                           Height="30" Width="30" Fill="LightYellow">
                </Rectangle>
                <Label HorizontalContentAlignment="Center" Content="{Binding Contenido}"
                       Height="{Binding ElementName=rectangulo, Path=Height}" 
                       Width="{Binding ElementName=rectangulo, Path=Width}">
                </Label>
            </Grid>
        </DataTemplate>

        <DataTemplate DataType="{x:Type Local:Bola}">
            <Grid ToolTip="{Binding Contenido}">
                <Ellipse Stroke="Black" StrokeThickness="1" Name="elipse"
                           Height="25" Width="25" Fill="LightYellow">
                </Ellipse>
                <Label HorizontalContentAlignment="Center" VerticalContentAlignment="Center" 
                       Content="{Binding Contenido}"
                       Height="{Binding ElementName=elipse, Path=Height}" 
                       Width="{Binding ElementName=elipse, Path=Width}">
                </Label>
            </Grid>
        </DataTemplate>

        <DataTemplate DataType="{x:Type Local:Flecha}">
            <Line X1="{Binding X1}" Y1="{Binding Y1}"
                  X2="{Binding X2}" Y2="{Binding Y2}"
                  Stroke="Black" StrokeThickness="1">
            </Line>
        </DataTemplate>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto" ></RowDefinition>
        </Grid.RowDefinitions>
        <TabControl Grid.Row="1" Margin="5" SelectedIndex="{Binding PestañaSeleccionada, UpdateSourceTrigger=PropertyChanged}">
            <TabItem Header="Árbol">
                <ItemsControl ItemsSource="{Binding ContenidoArbol}" BorderBrush="Transparent" Margin="0,0,20,20"
                              Name="ControlArbol">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas SizeChanged="WindowOnSizeChanged"></Canvas>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemContainerStyle>
                        <Style>
                            <Setter Property="Canvas.Left" Value="{Binding X}" />
                            <Setter Property="Canvas.Top" Value="{Binding Y}" />
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                </ItemsControl>
            </TabItem>
            <TabItem Header="Lista">
                <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Hidden">
                    <ItemsControl ItemsSource="{Binding ContenidoLista}" BorderBrush="Transparent" Margin="0,0,20,20">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Name="listaSTP" VerticalAlignment="Center" Orientation="Horizontal"></StackPanel>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemContainerStyle>
                            <Style>
                                <Setter Property="Canvas.Left" Value="{Binding X}" />
                                <Setter Property="Canvas.Top" Value="{Binding Y}" />
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                    </ItemsControl>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Tiempos">
                <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
                    <Grid HorizontalAlignment="Center">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        
                        <!--inserciones-->
                        <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" Margin="10" FontSize="14" FontWeight="Bold">Medir tiempo para inserciones</Label>
                        <Label Grid.Row="1" Grid.Column="0">Número de inserciones:</Label>
                        <TextBox  Grid.Row="1" Grid.Column="1" Width="100" Name="numInsercionesTXT"
                                  Text="{Binding NumeroInserciones, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                        <Button Grid.Row="1" Grid.Column="2" Height="25"
                                Command="{Binding ComenzarInsercionesCommand}">Comenzar</Button>
                        <GroupBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5" HorizontalAlignment="Center" Header="Opciones">
                            <StackPanel Orientation="Horizontal">
                                <StackPanel Margin="10">
                                    <RadioButton IsChecked="{Binding Opciones[0], UpdateSourceTrigger=PropertyChanged}"
                                                 >Valores al azar</RadioButton>
                                    <RadioButton IsChecked="{Binding Opciones[1], UpdateSourceTrigger=PropertyChanged}"
                                                 >Intervalo de valores</RadioButton>
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                        <TextBox Width="30" Text="{Binding IntervaloMin, UpdateSourceTrigger=PropertyChanged}"
                                                 ></TextBox>
                                        <Label>~</Label>
                                        <TextBox Width="30" Text="{Binding IntervaloMax, UpdateSourceTrigger=PropertyChanged}"
                                                 ></TextBox>
                                    </StackPanel>
                                </StackPanel>
                                <Separator BorderBrush="Black" BorderThickness="2">
                                    <Separator.LayoutTransform>
                                        <RotateTransform Angle="90" />
                                    </Separator.LayoutTransform>
                                </Separator>
                                <StackPanel Margin="10">
                                    <RadioButton IsChecked="{Binding Opciones[2], UpdateSourceTrigger=PropertyChanged}"
                                                 >Desordenados</RadioButton>
                                    <RadioButton IsChecked="{Binding Opciones[3], UpdateSourceTrigger=PropertyChanged}"
                                                 >Ordenados de menor a mayor</RadioButton>
                                    <RadioButton IsChecked="{Binding Opciones[4], UpdateSourceTrigger=PropertyChanged}"
                                                 >Ordenados de mayor a menor</RadioButton>
                                </StackPanel>
                            </StackPanel>
                        </GroupBox>

                        <StackPanel Grid.Row="3" Grid.ColumnSpan="5" Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <Label>Tiempo total acumulado:</Label>
                                <TextBlock Text="{Binding TiempoAcumuladoInserciones, UpdateSourceTrigger=PropertyChanged}"
                                           Margin="5" TextAlignment="Right" FontWeight="DemiBold"></TextBlock>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <Label>Tiempo medio por operación:</Label>
                                <TextBlock Text="{Binding TiempoMedioInserciones, UpdateSourceTrigger=PropertyChanged}"
                                           Margin="5" TextAlignment="Right" FontWeight="DemiBold"></TextBlock>
                            </StackPanel>
                        </StackPanel>

                        <!--extracciones-->
                        <Label Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="5" Margin="10" FontSize="14" FontWeight="Bold">
                            Medir tiempo para extracciones</Label>
                        <StackPanel Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="2" Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <Label>Tiempo total acumulado:</Label>
                                <TextBlock Text="{Binding TiempoAcumuladoExtracciones, UpdateSourceTrigger=PropertyChanged}"
                                           Margin="5" TextAlignment="Right" FontWeight="DemiBold"></TextBlock>
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <Label>Tiempo medio por operación:</Label>
                                <TextBlock Text="{Binding TiempoMedioExtracciones, UpdateSourceTrigger=PropertyChanged}"
                                           Margin="5" TextAlignment="Right" FontWeight="DemiBold"></TextBlock>
                            </StackPanel>
                            
                        </StackPanel>
                        <Button Grid.Row="5" Grid.Column="2" Height="25"
                                Command="{Binding ComenzarExtraccionesCommand}">Comenzar</Button>
                    </Grid>
                </ScrollViewer>
                
            </TabItem>
        </TabControl>

        <StackPanel Grid.Row="2" Orientation="Vertical" HorizontalAlignment="Center"
                    Visibility="{Binding VisibilidadControles, UpdateSourceTrigger=PropertyChanged}">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
                        Visibility="{Binding VisibilidadControlesAnimacion, UpdateSourceTrigger=PropertyChanged}">
                <Label>Duración de la animación:</Label>
                <Slider Width="200" Minimum="100" Maximum="2000"
                        Value="{Binding VelocidadAnimacion, UpdateSourceTrigger=PropertyChanged}"></Slider>
            </StackPanel>

            <StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Center">
                <GroupBox Header="Generar Heap al azar">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Label Grid.Column="0" Grid.Row="0">Número de nodos:</Label>
                        <Button Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Margin="5"
                                Command="{Binding GenerarHeapCommand}">Generar</Button>
                        <TextBox Grid.Column="1" Grid.Row="0" Margin="5" Width="30"
                                 Text="{Binding NumeroNodos, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                    </Grid>
                </GroupBox>
                <GroupBox Header="Insertar elemento">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Grid.Column="0">Elemento:</Label>
                        <TextBox Grid.Row="0" Grid.Column="1" Margin="5" Width="30"
                                 Text="{Binding ElementoInsertar, UpdateSourceTrigger=PropertyChanged}"></TextBox>
                        <Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="5"
                                Command="{Binding InsertarElementoCommand}">Insertar</Button>
                    </Grid>
                </GroupBox>
                <GroupBox Header="Operaciones">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Button Grid.Row="0" Grid.Column="0" Margin="5" Name="BorrarBTN"
                                Command="{Binding BorrarRaizCommand}">Borrar raíz</Button>
                        <!--<Button Grid.Row="0" Grid.Column="1" Margin="5" IsEnabled="False">Heapify</Button>-->
                        <Button Grid.Row="1" Grid.ColumnSpan="2" Margin="5" Name="StepBTN"
                                Command="{Binding StepCommand}">Step</Button>
                    </Grid>
                </GroupBox>
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>
